package com.ruoyi.project.filemgr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.filemgr.domain.ShareMonitor;
import com.ruoyi.project.filemgr.service.IShareMonitorService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 监控Controller
 * 
 * @author filemgr
 * @date 2024-02-02
 */
@RestController
@RequestMapping("/filemgr/sharemonitor")
public class ShareMonitorController extends BaseController {
    @Autowired
    private IShareMonitorService shareMonitorService;

    /**
     * 查询监控列表
     */
    @PreAuthorize("@ss.hasPermi('filemgr:sharemonitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShareMonitor shareMonitor) {
        shareMonitor.setUserId(getUserId());
        startPage();
        List<ShareMonitor> list = shareMonitorService.selectShareMonitorList(shareMonitor);
        return getDataTable(list);
    }

    /**
     * 导出监控列表
     */
    @PreAuthorize("@ss.hasPermi('filemgr:sharemonitor:export')")
    @Log(title = "监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShareMonitor shareMonitor) {
        List<ShareMonitor> list = shareMonitorService.selectShareMonitorList(shareMonitor);
        ExcelUtil<ShareMonitor> util = new ExcelUtil<ShareMonitor>(ShareMonitor.class);
        util.exportExcel(response, list, "监控数据");
    }

    /**
     * 获取监控详细信息
     */
    @PreAuthorize("@ss.hasPermi('filemgr:sharemonitor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(shareMonitorService.selectShareMonitorById(id));
    }

    /**
     * 新增监控
     */
    @PreAuthorize("@ss.hasPermi('filemgr:sharemonitor:add')")
    @Log(title = "监控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShareMonitor shareMonitor) {
        return toAjax(shareMonitorService.insertShareMonitor(shareMonitor));
    }

    /**
     * 修改监控
     */
    @PreAuthorize("@ss.hasPermi('filemgr:sharemonitor:edit')")
    @Log(title = "监控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShareMonitor shareMonitor) {
        return toAjax(shareMonitorService.updateShareMonitor(shareMonitor));
    }

    /**
     * 删除监控
     */
    @PreAuthorize("@ss.hasPermi('filemgr:sharemonitor:remove')")
    @Log(title = "监控", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(shareMonitorService.deleteShareMonitorByIds(ids));
    }
}
